package com.learn.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

class NThread implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if(i % 2 == 0){
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
    }
}

class NuThread implements Callable {

    @Override
    public Object call() throws Exception {
        for (int i = 0; i < 100; i++) {
            if(i % 2 != 0){
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
        return null;
    }
}

public class ThreadPool {
    public static void main(String[] args) {
        //提供指定现场数量的线程池
        ExecutorService service = Executors.newFixedThreadPool(10);
        NuThread nuThread = new NuThread();
        FutureTask t = new FutureTask(nuThread);

        service.execute(new NThread());//适用于Runnable
        service.submit(new Thread(t));//适用于Callable

        service.shutdown();
    }
}
